<?php
include "Class/EasyMySQL.php";

    $mysql = new EasyMySQL();
    if(!$mysql->Connect())  return;

    $method = $_REQUEST["Method"];
    $data = file_get_contents('php://input', 'r');
    $data = iconv("GB2312", "UTF-8//IGNORE", $data);

    if($method == "Select")
    {
        $Names = "Personnel.UID AS UID,Personnel.Name AS Name,Personnel.Username AS Username,
                Personnel.Password AS Password,Personnel.Image AS Image,
                PersonnelGroup.UID AS PersonnelGroupUID,PersonnelGroup.Name AS PersonnelGroupName,
                Personnel.Sex AS Sex,Personnel.ID AS ID,Personnel.Birthday AS Birthday,
                Personnel.Phone AS Phone,Personnel.Emergency AS Emergency,
                City.UID AS CityUID,City.Name AS CityName,
                Province.UID AS ProvinceUID,Province.Name AS ProvinceName,
                Personnel.WebChat AS WebChat,Personnel.CreateTime AS CreateTime";
        $page = $_REQUEST["Page"];
        $mysql->Select("Personnel", $Names)->WhereSelect($data)->LeftJoin("PersonnelGroup", "Personnel.PersonnelGroupUID=PersonnelGroup.UID")
            ->LeftJoin("City", "City.UID=Personnel.CityUID")->LeftJoin("Province", "City.ProvinceUID=Province.UID")->Limit($page)->QuerySelect();
    }
    else if($method == "Insert")
    {
        $mysql->Insert("Personnel")->InsertColumns("Name,Username,Password,Image,PersonnelGroupUID,Sex,ID,Birthday,Phone,Emergency,CityUID,WebChat")->InsertValues($data, 12)->Query();
    }
    else if($method == "Update")
    {
        $array = explode("#", $data);
        $mysql->Update("Personnel")->UpdateSet($array[0])->WhereUpdate("UID=".$array[1])->Query();
    }
    else if($method == "Delete")
    {
        $mysql->Delete("Personnel")->WhereDelete("UID", $data)->Query();
    }
    else if($method == "SelectCount")
    {
        $mysql->SelectCount("Personnel")->WhereSelect($data)->QueryCount();
    }

    $mysql->Close();
?>